package adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import blogic.AccesBussineLogic;
import blogic.BusinessLogic;

import com.trip_memories.R;

import dbmodels.Album;

public class MyArrayAdapter extends ArrayAdapter<Album> {

	private final Context context;
	private final Album[] values;
	private final BusinessLogic bl;

	public MyArrayAdapter(Context context, Album[] objects) {
		super(context, R.layout.view_album, objects);
		this.context = context;
		this.values = objects;
		bl = AccesBussineLogic.getBussinesLogic(context);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View rowView = inflater.inflate(R.layout.albums_list, parent, false);
		TextView name = (TextView) rowView.findViewById(R.id.album_name);
		TextView author = (TextView) rowView.findViewById(R.id.album_author);
		TextView count = (TextView) rowView.findViewById(R.id.album_count);
		name.setText(name.getText() + values[position].getName());
		author.setText(author.getText() + bl.UserName(values[position].getUserid()));
		count.setText(count.getText() +""+ bl.NumberOfPhotoInAlbum(values[position].getId()));
		return rowView;
	}

	@Override
	public void setNotifyOnChange(boolean notifyOnChange) {
		super.setNotifyOnChange(notifyOnChange);
		this.notifyDataSetChanged();
	}
}
